package com.example.mybank.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.mybank.entity.Buycount;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface BuycountMapper extends BaseMapper<Buycount> {
    @Select("SELECT * from buycount " +
            "where users=#{userID} and engine=#{engineID} " +
                "and time_screen > date_sub(now(),interval #{mins} minute ) " +
            "ORDER BY time_screen DESC ")
    public List<Buycount> selectByUserEngineInmins(Long userID,Long engineID,int mins);

    @Update("UPDATE buycount " +
            "SET count=count+1 " +
            "WHERE users=#{usersID} and product=#{productID} and count<count_max")
    public int increase(Long usersID,Long productID);
}
